package com.tjbaobao.videoplayol.utils;


import android.os.AsyncTask;
import com.google.gson.Gson;
import com.tjbaobao.framework.utils.NetworkUtil;
import com.tjbaobao.videoplayol.message.response.FileUploadResponse;


public abstract class UploadAsyncTask extends AsyncTask<String, Integer, FileUploadResponse> {

	protected String path ;
	public UploadAsyncTask(String path) {
		this.path = path ;
	}

	@Override
	protected FileUploadResponse doInBackground(String... params) {
		String result = new NetworkUtil().uploadFile(ConstantUtil.UPLOAD_SERVER_URL, path);
		if(result!=null&&!result.equals(""))
		{
			FileUploadResponse fileResponse = new Gson().fromJson(result,FileUploadResponse.class);
			return fileResponse;
		}
		return null;
	}

	@Override
	protected void onPostExecute(FileUploadResponse result) {
		if(result!=null)
		{
			String code = result.getFileCode();
			onSuccess(code);
		}
		else
		{
			onFail();
		}
		super.onPostExecute(result);
	}
	protected abstract void onSuccess(String code);
	protected abstract void onFail();

	@Override
	protected void onProgressUpdate(Integer... values) {
		super.onProgressUpdate(values);
	}
}
